#******************************************************************
#
# Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Import('env')

transport = env.get('TARGET_TRANSPORT')
if 'BLE' in transport:
        # Only supported for ethernet and WiFi.
        Return()

arduino_simplecs_env = env.Clone()
######################################################################
# Build flags
######################################################################
arduino_simplecs_env.PrependUnique(CPPPATH = [
		'../../../../../logger/include',
		'../../../../../stack/include',
		'../../../../../../oc_logger/include'
		])

arduino_simplecs_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
arduino_simplecs_env.AppendUnique(CPPDEFINES = ['TB_LOG'])

arduino_simplecs_env.PrependUnique(LIBS = ['octbstack', 'ocsrm', 'connectivity_abstraction','coap'])

arduino_simplecs = arduino_simplecs_env.Program('SimpleClientServer', 'ocserver.cpp')
env.CreateBin('SimpleClientServer')

i_arduino_simplecs = arduino_simplecs_env.Install(env.get('BUILD_DIR'), arduino_simplecs)

#The map file is intermediate file, make sure it's removed when clean build
arduino_simplecs_env.Clean(arduino_simplecs, 'SimpleClientServer.map')

Alias('arduino_simplecs', i_arduino_simplecs)
env.AppendTarget('arduino_simplecs')

if(arduino_simplecs_env['UPLOAD'] == True):
	from sys import platform as _platform
	if _platform == "linux" or _platform == "linux2":
		arduino_simplecs_env.Upload(env.get('BUILD_DIR') + '/resource/csdk/stack/samples/arduino/SimpleClientServer/ocserver/SimpleClientServer.hex')
	else:
		print 'Please use appropriate install method for your developing machine. Linux is the only supported platform right now.'
